import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import Client from '@/client'

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  }, {
    path: '/ForgetPassword',
    component: () => import('@/views/login/ForgetPassword'),
    hidden: true, meta: {
      title: '前台',
      type: "Client",

    },
  },

  {
    path: '/Register',
    component: () => import('@/views/login/Register'),
    hidden: true,
    meta: {
      title: '前台',
      type: "Client",

    },
  },
  {
    path: '/404',

    component: () => import('@/views/404'),
    hidden: true,
    meta: {
      type: "foreground",
    },
  },


  { path: '*', redirect: '/', hidden: true }
]
export const constantHomeRoutes = [
  {
    path: '/Client/Index',
    component: Client,
    redirect: "/Client/Home",
    meta: {
      title: '前台',
      type: "Client",

    },
    children: [{
      path: '/Client/Home',
      component: () => import('@/views/Client/Home'),
      name: 'Home',
      hidden: true,
      meta: {
        type: "Client",
        title: '首页',

      }
    }, {
      path: '/Client/MyUserInfo',
      component: () => import('@/views/Client/MyUserCenter/MyUserInfo'),
      name: 'ClientMyUserInfo',
      hidden: true,
      meta: {
        type: "Client",
        title: '我的个人信息',

      }
    }, {
      path: '/Client/TopicList',
      component: () => import('@/views/Client/TopicList'),
      name: 'ClientTopicList',
      hidden: true,
      meta: {
        type: "Client",
        title: '交流列表',

      }
    }, {
      path: '/Client/TopicSearch',
      component: () => import('@/views/Client/TopicSearch'),
      name: 'ClientTopicSearch',
      hidden: true,
      meta: {
        type: "Client",
        title: '交流搜索',

      }
    }, {
      path: '/Client/TopicDetail',
      component: () => import('@/views/Client/TopicDetail'),
      name: 'ClientTopicDetail',
      hidden: true,
      meta: {
        type: "Client",
        title: '话题详情',

      }
    }, {
      path: '/Client/TopicTypeList',
      component: () => import('@/views/Client/TopicTypeList'),
      name: 'ClientTopicTypeList',
      hidden: true,
      meta: {
        type: "Client",
        title: '话题类别',

      }
    }, {
      path: '/Client/TaHome',
      component: () => import('@/views/Client/TaHome'),
      name: 'ClientTaHome',
      hidden: true,
      meta: {
        type: "Client",
        title: '它的主页',

      }
    },]
  },
]


export const asyncRoutes = [

  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    meta: {
      icon: "el-icon-s-home",
      roles: [0, 2],
    },
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      name: 'dashboard',
      meta: {
        roles: [0, 2],
        icon: "el-icon-s-home",
        title: '控制台',
        noCache: true
      }
    }]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/Admin/UserList',
    meta: {
      title: '用户',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'UserList',
      component: () => import('@/views/Admin/UserList'),
      name: 'UserList',
      meta: {
        title: '用户',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/TopicType',
    component: Layout,
    redirect: '/Admin/TopicTypeList',
    meta: {
      title: '话题管理',
      icon: "el-icon-s-help",
      roles: [0],

    },
    children: [{
      path: 'TopicTypeList',
      component: () => import('@/views/Admin/TopicTypeList'),
      name: 'TopicTypeList',
      meta: {
        title: '话题类型',
        roles: [0],
        icon: "el-icon-menu",
        noCache: true
      }
    }, {
      path: 'TopicList',
      component: () => import('@/views/Admin/TopicList'),
      name: 'TopicList',
      meta: {
        title: '分享话题',
        roles: [0],
        icon: "el-icon-share",
        noCache: true
      }
    }, {
      path: 'CommentList',
      component: () => import('@/views/Admin/CommentList'),
      name: 'CommentList',
      meta: {
        title: '话题评论',
        roles: [0],
        icon: "el-icon-bell",
        noCache: true
      }
    }, {
      path: 'TopicRecordList',
      component: () => import('@/views/Admin/TopicRecordList'),
      name: 'TopicRecordList',
      meta: {
        title: '浏览记录',
        roles: [0],
        icon: "el-icon-view",
        noCache: true
      }
    }, {
      path: 'TopicCollectList',
      component: () => import('@/views/Admin/TopicCollectList'),
      name: 'TopicCollectList',
      meta: {
        title: '话题收藏',
        roles: [0],
        icon: "el-icon-paperclip",
        noCache: true
      }
    }, {
      path: 'TopicAnalyse',
      component: () => import('@/views/Admin/TopicAnalyse'),
      name: 'TopicAnalyse',
      meta: {
        title: '话题分析',
        roles: [0],
        icon: "el-icon-data-analysis",
        noCache: true
      }
    },
    ]
  },
  {
    path: '/TestModuleList',
    component: Layout,
    redirect: '/Admin/TestModuleList',
    meta: {
      title: '动态测试模块',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'TestModuleList',
      component: () => import('@/views/Admin/TestModuleList'),
      name: 'TestModuleList',
      meta: {
        title: '动态测试主表',
        roles: [0],
        noCache: true
      }
    }]
  },






]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...constantHomeRoutes, ...asyncRoutes]
})

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
